<?php

namespace yjHyperfAdminPligin\Email\Driver;

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use Psr\Container\ContainerInterface;

/**
 * @Notes:【】
 * @Date: 2022-12-02 22:05
 */
class PHPMailerDriver
{
    private ContainerInterface $container;

    private PHPMailer $PHPMailer;

    public function __construct()
    {
        $this->PHPMailer = $this->init();
    }

    public function init()
    {
        /** @var PHPMailer $PHPMailer */
        $PHPMailer = make(PHPMailer::class, ['exceptions' => true]);
        //Server settings
        $PHPMailer->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
        $PHPMailer->isSMTP();                                            //Send using SMTP
        $PHPMailer->Host = 'smtp.qq.com';                     //Set the SMTP server to send through
        $PHPMailer->SMTPAuth = true;                                   //Enable SMTP authentication
        $PHPMailer->Username = '1324028467@qq.com';                     //SMTP username
        $PHPMailer->Password = 'tivafgtnjmjyjeib';                               //SMTP password
        $PHPMailer->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
        $PHPMailer->Port = 465;

        //Recipients
        $PHPMailer->setFrom('1324028467@qq.com', 'Mailer');
        $PHPMailer->addAddress('1324028467@qq.com', 'Joe 111User');     //Add a recipient
//        $PHPMailer->addAddress('ellen@example.com');               //Name is optional
//        $PHPMailer->addReplyTo('info@example.com', 'Information');
//        $PHPMailer->addCC('cc@example.com');
//        $PHPMailer->addBCC('bcc@example.com');

        return $PHPMailer;
    }

    public function send()
    {
        $PHPMailer = $this->PHPMailer;
        //Content
        $PHPMailer->isHTML(true);                                  //Set email format to HTML
        $PHPMailer->Subject = 'Here is the subject';
        $PHPMailer->Body = 'This is the HTML message body <b>in bold!</b>';
        $PHPMailer->AltBody = 'This is the body in plain text for non-HTML mail clients';

        return $PHPMailer->send();
    }
}